package net.zoneland.knowledge.dao;

import net.zoneland.knowledge.model.OpLog;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

@Mapper
public interface OpLogMapper {
    @Delete({
        "delete from AITK_OPLOG",
        "where ID = #{id,jdbcType=VARCHAR}"
    })
    int deleteByPrimaryKey(String id);

    @Insert({
        "insert into AITK_OPLOG (ID, SYSTEM_ID, ",
        "TOKEN, VISIT_TYPE, ",
        "USER_ID, SESSION_ID, ",
        "REQUEST_ID, PARENT_REQUEST_ID, ",
        "COMPONENT_ID, CATEGORY_LIST, ",
        "QUESTION_ID, REQUEST_URL, ",
        "REQUEST_PARAM, ELEMENT_ID, ",
        "OPLOG_ACTION, DEVICE, ",
        "REFERER, USER_AGENT, ",
        "OS, BROWSER, IP, ",
        "UA_DEVICE, CREATE_TIME, USER_NAME, ",
        "CMP_DN,CMP_NAME)",
        "values (#{id,jdbcType=VARCHAR}, #{systemId,jdbcType=VARCHAR}, ",
        "#{token,jdbcType=VARCHAR}, #{visitType,jdbcType=VARCHAR}, ",
        "#{userId,jdbcType=VARCHAR}, #{sessionId,jdbcType=VARCHAR}, ",
        "#{requestId,jdbcType=VARCHAR}, #{parentRequestId,jdbcType=VARCHAR}, ",
        "#{componentId,jdbcType=VARCHAR}, #{categoryList,jdbcType=VARCHAR}, ",
        "#{questionId,jdbcType=VARCHAR}, #{requestUrl,jdbcType=VARCHAR}, ",
        "#{requestParam,jdbcType=VARCHAR}, #{elementId,jdbcType=VARCHAR}, ",
        "#{action,jdbcType=VARCHAR}, #{device,jdbcType=VARCHAR}, ",
        "#{referer,jdbcType=VARCHAR}, #{userAgent,jdbcType=VARCHAR}, ",
        "#{os,jdbcType=VARCHAR}, #{browser,jdbcType=VARCHAR}, #{ip,jdbcType=VARCHAR}, ",
        "#{uaDevice,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP},",
        "#{userName,jdbcType=VARCHAR}, #{cmpDn,jdbcType=VARCHAR},#{cmpName,jdbcType=VARCHAR})"
    })
    int insert(OpLog record);

    @InsertProvider(type=OpLogSqlProvider.class, method="insertSelective")
    int insertSelective(OpLog record);

    @Select({
        "select",
        "ID, SYSTEM_ID, TOKEN, VISIT_TYPE, USER_ID, SESSION_ID, REQUEST_ID, PARENT_REQUEST_ID, ",
        "COMPONENT_ID, CATEGORY_LIST, QUESTION_ID, REQUEST_URL, REQUEST_PARAM, ELEMENT_ID, ",
        "OPLOG_ACTION, DEVICE, REFERER, USER_AGENT, OS, BROWSER, IP, UA_DEVICE, CREATE_TIME,",
        "USER_NAME, CMP_DN, CMP_NAME",
        "from AITK_OPLOG",
        "where ID = #{id,jdbcType=VARCHAR}"
    })
    @Results({
        @Result(column="ID", property="id", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="SYSTEM_ID", property="systemId", jdbcType=JdbcType.VARCHAR),
        @Result(column="TOKEN", property="token", jdbcType=JdbcType.VARCHAR),
        @Result(column="VISIT_TYPE", property="visitType", jdbcType=JdbcType.VARCHAR),
        @Result(column="USER_ID", property="userId", jdbcType=JdbcType.VARCHAR),
        @Result(column="SESSION_ID", property="sessionId", jdbcType=JdbcType.VARCHAR),
        @Result(column="REQUEST_ID", property="requestId", jdbcType=JdbcType.VARCHAR),
        @Result(column="PARENT_REQUEST_ID", property="parentRequestId", jdbcType=JdbcType.VARCHAR),
        @Result(column="COMPONENT_ID", property="componentId", jdbcType=JdbcType.VARCHAR),
        @Result(column="CATEGORY_LIST", property="categoryList", jdbcType=JdbcType.VARCHAR),
        @Result(column="QUESTION_ID", property="questionId", jdbcType=JdbcType.VARCHAR),
        @Result(column="REQUEST_URL", property="requestUrl", jdbcType=JdbcType.VARCHAR),
        @Result(column="REQUEST_PARAM", property="requestParam", jdbcType=JdbcType.VARCHAR),
        @Result(column="ELEMENT_ID", property="elementId", jdbcType=JdbcType.VARCHAR),
        @Result(column="OPLOG_ACTION", property="action", jdbcType=JdbcType.VARCHAR),
        @Result(column="DEVICE", property="device", jdbcType=JdbcType.VARCHAR),
        @Result(column="REFERER", property="referer", jdbcType=JdbcType.VARCHAR),
        @Result(column="USER_AGENT", property="userAgent", jdbcType=JdbcType.VARCHAR),
        @Result(column="OS", property="os", jdbcType=JdbcType.VARCHAR),
        @Result(column="BROWSER", property="browser", jdbcType=JdbcType.VARCHAR),
        @Result(column="IP", property="ip", jdbcType=JdbcType.VARCHAR),
        @Result(column="UA_DEVICE", property="uaDevice", jdbcType=JdbcType.VARCHAR),
        @Result(column="CREATE_TIME", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="USER_NAME", property="userName", jdbcType=JdbcType.VARCHAR),
        @Result(column="CMP_DN", property="cmpDn", jdbcType=JdbcType.VARCHAR),
        @Result(column="CMP_NAME", property="cmpName", jdbcType=JdbcType.VARCHAR)
    })
    OpLog selectByPrimaryKey(String id);

    @UpdateProvider(type=OpLogSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(OpLog record);

    @Update({
        "update AITK_OPLOG",
        "set SYSTEM_ID = #{systemId,jdbcType=VARCHAR},",
          "TOKEN = #{token,jdbcType=VARCHAR},",
          "VISIT_TYPE = #{visitType,jdbcType=VARCHAR},",
          "USER_ID = #{userId,jdbcType=VARCHAR},",
          "SESSION_ID = #{sessionId,jdbcType=VARCHAR},",
          "REQUEST_ID = #{requestId,jdbcType=VARCHAR},",
          "PARENT_REQUEST_ID = #{parentRequestId,jdbcType=VARCHAR},",
          "COMPONENT_ID = #{componentId,jdbcType=VARCHAR},",
          "CATEGORY_LIST = #{categoryList,jdbcType=VARCHAR},",
          "QUESTION_ID = #{questionId,jdbcType=VARCHAR},",
          "REQUEST_URL = #{requestUrl,jdbcType=VARCHAR},",
          "REQUEST_PARAM = #{requestParam,jdbcType=VARCHAR},",
          "ELEMENT_ID = #{elementId,jdbcType=VARCHAR},",
          "OPLOG_ACTION = #{action,jdbcType=VARCHAR},",
          "DEVICE = #{device,jdbcType=VARCHAR},",
          "REFERER = #{referer,jdbcType=VARCHAR},",
          "USER_AGENT = #{userAgent,jdbcType=VARCHAR},",
          "OS = #{os,jdbcType=VARCHAR},",
          "BROWSER = #{browser,jdbcType=VARCHAR},",
          "IP = #{ip,jdbcType=VARCHAR},",
          "UA_DEVICE = #{uaDevice,jdbcType=VARCHAR},",
          "CREATE_TIME = #{createTime,jdbcType=TIMESTAMP}",
          "USER_NAME = #{userName,jdbcType=VARCHAR}",
          "CMP_DN = #{cmpDn,jdbcType=VARCHAR}",
          "CMP_NAME = #{cmpName,jdbcType=VARCHAR}",
        "where ID = #{id,jdbcType=VARCHAR}"
    })
    int updateByPrimaryKey(OpLog record);
}